<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta charset="UTF-8">
<title>失物招领后台管理</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="../css/bootstrap.css" />
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/main.css" />
<script type="text/javascript" src="../js/bootstrap.js"></script>
<script type="text/javascript" src="../js/scrollspy.js"></script>
<link href="../fonts/css/font-awesome.css" rel="stylesheet">

<!-- Toastr style -->
<link href="../css/toastr.min.css" rel="stylesheet">

<link href="../css/animate.css" rel="stylesheet">
<link href="../css/style.css" rel="stylesheet">
<!--sweetalert-->
<link rel="stylesheet" href="../css/sweetalert.css" />
</head>

<body>
	<div id="wrapper">
		<!--左侧导航栏-->
		<nav class="navbar-default navbar-static-side" role="navigation">
		<div class="sidebar-collapse">
			<ul class="nav metismenu" id="side-menu">
				
				<li><a href="#"><i class="fa fa-th-large"></i> <span
						class="nav-label">信息管理</span> <span class="fa arrow"></span></a>
					<ul class="nav nav-second-level collapse">
						
						<li><a href="matchitem.jsp">招领配对</a></li>
						<li><a href="findingrecord.jsp">招领记录</a></li>
					</ul></li>
				
			</ul>

		</div>
		</nav>
		<!--
            	作者：1462859532@qq.com
            	时间：2017-03-29
            	描述：右侧导航栏
            -->
		<div id="page-wrapper" class="gray-bg">
			<div class="row border-bottom">
				<nav class="navbar navbar-static-top" role="navigation"
					style="margin-bottom: 0">
				<div class="navbar-header">
					<a class="navbar-minimalize minimalize-styl-2 btn btn-primary "
						href="#"><i class="fa fa-bars"></i> </a>
				</div>
				<ul class="nav navbar-top-links navbar-right">
					<li><span class="m-r-sm text-muted welcome-message">欢迎来到失物招领后台管理</span>
					</li>
					<li><a href="login.jsp"> <i class="fa fa-sign-out"></i> 注销
					</a></li>
				</ul>
				</nav>
			</div>
			<div class="row wrapper border-bottom white-bg page-heading">
				<div class="col-lg-10">

					<ol class="breadcrumb">
						<li><a>地点</a></li>
						<li class="active"><strong>招领记录</strong></li>
					</ol>
				</div>
				<div class="col-lg-2"></div>
			</div>

			<div class="wrapper wrapper-content  animated fadeInRight article">
				<div class="pull-right">
					<div class="input-group">
						<input placeholder="按描述查找" class="input-sm form-control"
							type="text" id="querybydesc"> <span
							class="input-group-btn">
							<button type="button" class="btn btn-sm btn-primary" id="query">
								查询</button>
						</span>
					</div>
				</div>
				<div class="row">

					<!--失物信息-->
					<div class="col-md-12">
						<div class="losingadmin panel panel-default">
							<div class="panel-body">
								<table class="losingtable table table-striped"
									cellpadding="20px" cellspacing="5" id="losingshow">
									<thead>
										<tr class="active">
											<th style="width: 25%">物品</th>
											<th style="width: 25%">招领人</th>
											<th style="width: 25%">联系电话</th>
											<th style="width: 25%">操作</th>
										</tr>
									</thead>
									<tbody id="locappend">

									</tbody>
								</table>
							</div>
							<div class="panel-footer">
								<div id="pagerole">
									<nav aria-label="Page navigation">
									<ul class="pagination">
										<li id="findingpagevalue" style="display: none"></li>
										<li id="findingpagecount" style="display: none"></li>
										<li><a href="#" id="itemfirst">首页</a></li>
										<li><a href="#" id="itemprev">上一页</a></li>
										<li><a href="#" id="itemnext">下一页</a></li>
										<li><a href="#" id="itemlast">尾页</a></li>
									</ul>
									</nav>
								</div>
							</div>


						</div>
					</div>
				</div>
			</div>
		</div>

	</div>
	<div class="footer">
		<div>
			<strong>Copyright</strong>版权所有 &copy; 2017
		</div>
	</div>
	<div>
		<div class="modal fade" id="modeladd" tabindex="-1" role="dialog">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title">招领信息</h4>
					</div>
					<div class="modal-body">
						<div class="form-group">
							<!--
                                	作者：1462859532@qq.com
                                	时间：2017-03-28
                                	描述：可以在上面做个表单验证
                                -->
							<label for="locname" class="control-label">图片</label> <img
								id="imgpic" style="width: 500px; height: 300px" />
						</div>

						<div class="form-group">
							<label for="phone" class="control-label" id="detail">详情描述</label>
						</div>
					</div>
					<div class="modal-footer">

						<button type="button" class="btn btn-default" id="addclose"
							data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="sure"
							data-dismiss="modal">确定</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!--模态框关闭-->

	<!-- Mainly scripts -->
	<script src="../js/jquery.js"></script>
	<script src="../js/bootstrap.min.js"></script>
	<script src="../js/jquery.metisMenu.js"></script>
	<script src="../js/jquery.slimscroll.min.js"></script>

	<!-- Custom and plugin javascript -->
	<script src="../js/inspinia.js"></script>
	<script src="../js/pace.min.js"></script>
	<script type="text/javascript" src="../js/sweetalert.min.js"></script>
	<script type="text/javascript">
	    $.ajax({
	    	type:"post",
	    	url:"../admin/queryfinding.action",
	    	dataType:"json",
	    	success:function(data){
	    		if(data.length>=5){
  				  length=5;
  			  }else{
  				  length=data.length;
  			  }
  			  for(var i=0;i<length;i++){
  				 // alert(data[0].currentpage);
  				  $("#locappend").append('<tr><td style="display: none;">'+
		      						  data[i].findRecordsId+'</td><td>'+
		      						  data[i].itemsDescription+'</td><td>'+
		      						  data[i].userName+'</td><td>'+
		      						  data[i].phone+'</td><td>'+
		      						  '<button class="btn btn-primary agree" onclick="agree(this)">查看</button>'+
		      						  '</td></tr>');
  				  $("#findingpagevalue").text(Math.round(parseInt(data[0].pageindex)/5));
  			  }
  			  $("#findingpagecount").text(data[0].count);
	    	}
	    })
	     $("#itemfirst").click(function(){
	    		 
	    		  $.ajax({
    				  type:"post",
		    		  url:"../admin/queryfinding.action?currentpage=0",
		    		  dataType:"json",
		    		  data:{"itemsDescription": $("#querybydesc").val()},
		    		  success:function(data){
		    			  $("#locappend tr").remove();
		    			  if(data.length>=5){
		      				  length=5;
		      			  }else{
		      				  length=data.length;
		      			  }
		    			  for(var i=0;i<length;i++){
		    				  $("#locappend").append('<tr><td style="display: none;">'+
		      						  data[i].findRecordsId+'</td><td>'+
		      						  data[i].itemsDescription+'</td><td>'+
		      						  data[i].userName+'</td><td>'+
		      						  data[i].phone+'</td><td>'+
		      						  '<button class="btn btn-primary agree" onclick="agree(this)">查看</button>'+
		      						  '</td></tr>');
		      				  $("#findingpagevalue").text(Math.round(parseInt(data[0].pageindex)/5));
		      			  }
		      			  $("#findingpagecount").text(data[0].count);
		    		  }
    			  })
	    	  });
	    	  //上一页
	    	  $("#itemprev").click(function(){
	    		  var itemsDescription=$("#querybydesc").val();
	    		 
	    		  //alert(123);
	    		  //当前页
	    		  var pagecurrent=$("#findingpagevalue").text();
	    		  //总页数
	    		  var pagecount=$("#findingpagecount").text();
	    		  if(pagecurrent==0){
	    			  alert("不好意思，已经是第一页了");
	    		  }
	    		  else{
	    			  $.ajax({
	    				  type:"post",
			    		  url:"../admin/queryfinding.action?currentpage="+(parseInt(pagecurrent)-1),
			    		  dataType:"json",
			    		  data:{"itemsDescription": $("#querybydesc").val()},
			    		  success:function(data){
			    			  $("#locappend tr").remove();
			    			  if(data.length>=5){
			      				  length=5;
			      			  }else{
			      				  length=data.length;
			      			  }
			    			  for(var i=0;i<length;i++){
			    				  $("#locappend").append('<tr><td style="display: none;">'+
			      						  data[i].findRecordsId+'</td><td>'+
			      						  data[i].itemsDescription+'</td><td>'+
			      						  data[i].userName+'</td><td>'+
			      						  data[i].phone+'</td><td>'+
			      						  '<button class="btn btn-primary agree" onclick="agree(this)">查看</button>'+
			      						  '</td></tr>');
			      				  $("#findingpagevalue").text(Math.round(parseInt(data[0].pageindex)/5));
			      			  }
			      			  $("#findingpagecount").text(data[0].count);
			    		  }
	    			  })
	    		  }
	    		 // 
	    	  });
	    	  //下一页
	    	  $("#itemnext").click(function(){
	    		
	    		  var itemsDescription=$("#querybydesc").val();
	    		  //当前页
	    		  var pagecurrent=$("#findingpagevalue").text();
	    		  //总页数
	    		  var pagecount=$("#findingpagecount").text();
	    		  if((parseInt(pagecurrent)+1)*5>=pagecount){
	    			  alert("不好意思，已经是最后一页了");
	    		  }else{
	    			  $.ajax({
	    				  type:"post",
			    		  url:"../admin/queryfinding.action?currentpage="+(parseInt(pagecurrent)+1),
			    		  dataType:"json",
			    		  data:{"itemsDescription": $("#querybydesc").val()},
			    		  success:function(data){
			    			  $("#locappend tr").remove();
			    			  if(data.length>=5){
			      				  length=5;
			      			  }else{
			      				  length=data.length;
			      			  }
			    			  for(var i=0;i<length;i++){
			    				  $("#locappend").append('<tr><td style="display: none;">'+
			      						  data[i].findRecordsId+'</td><td>'+
			      						  data[i].itemsDescription+'</td><td>'+
			      						  data[i].userName+'</td><td>'+
			      						  data[i].phone+'</td><td>'+
			      						  '<button class="btn btn-primary agree" onclick="agree(this)">查看</button>'+
			      						  '</td></tr>');
			      				  $("#findingpagevalue").text(Math.round(parseInt(data[0].pageindex)/5));
			      			  }
			      			  $("#findingpagecount").text(data[0].count);
			    		  }
	    			  })

	    		  }
	    	  });
	    	  //最后一页
	    	  $("#itemlast").click(function(){
	    		  var itemsDescription=$("#querybydesc").val();
	    		 
	    		  var last;
	    		  if(parseInt($("#findingpagecount").text())%5!=0){
	    			  last=parseInt(parseInt($("#findingpagecount").text())/5);
	    		  }else{
	    			  last=parseInt($("#findingpagecount").text())/5-1;
	    		  }
	    		  $.ajax({
    				  type:"post",
		    		  url:"../admin/queryfinding.action?currentpage="+last,
		    		  data:{"itemsDescription": $("#querybydesc").val()},
		    		  dataType:"json",
		    		  success:function(data){
		    			  $("#locappend tr").remove();
		    			  if(data.length>=5){
		      				  length=5;
		      			  }else{
		      				  length=data.length;
		      			  }
		    			  for(var i=0;i<length;i++){
		    				  $("#locappend").append('<tr><td style="display: none;">'+
		      						  data[i].findRecordsId+'</td><td>'+
		      						  data[i].itemsDescription+'</td><td>'+
		      						  data[i].userName+'</td><td>'+
		      						  data[i].phone+'</td><td>'+
		      						  '<button class="btn btn-primary agree" onclick="agree(this)">查看</button>'+
		      						  '</td></tr>');
		      				  $("#findingpagevalue").text(Math.round(parseInt(data[0].pageindex)/5));
		      			  }
		      			  $("#findingpagecount").text(data[0].count);
		    		  }
    			  })
	    	  });
	    	  $("#query").click(function(){
	  			var itemsDescription=$("#querybydesc").val();
	  	    	 $.ajax({
	  				  type:"post",
	  	    		  url:"../admin/queryfinding.action",
	  	    		  dataType:"json",
	  	    		  data:{"ItemsDescription":itemsDescription},
	  	    		  success:function(data){
	  	    			  $("#locappend tr").remove();
	  	    			if(data.length>=5){
		      				  length=5;
		      			  }else{
		      				  length=data.length;
		      			  }
		    			  for(var i=0;i<length;i++){
		    				  $("#locappend").append('<tr><td style="display: none;">'+
		      						  data[i].findRecordsId+'</td><td>'+
		      						  data[i].itemsDescription+'</td><td>'+
		      						  data[i].userName+'</td><td>'+
		      						  data[i].phone+'</td><td>'+
		      						  '<button class="btn btn-primary agree" onclick="agree(this)">查看</button>'+
		      						  '</td></tr>');
		      				  $("#findingpagevalue").text(Math.round(parseInt(data[0].pageindex)/5));
		      			  }
		      			  $("#findingpagecount").text(data[0].count);
	  	    		  }
	  			  })
	  	    	
	  		})
	  		
	  		function agree(e){
	    		  $("#modeladd").modal('show');
	    		  $("#detail").text("");
	    		  var id=$(e).parent().parent().children(":first").text();
	    		  $.ajax({
    				  type:"post",
    				  url:"../admin/queryfinding.action?findRecordsId="+id,
    				  dataType:"json",
    				  success:function(data){
    					  $("#imgpic").attr("src","/pic/"+data[0].picture);
    					  $("#detail").append(data[0].detaildescritton);
    				  },
    				  error:function(){
    					  swal("不好意思", "查看失败)", "error");
    				  }
    			  })
	    	  }
	
	</script>
</body>

</html>